home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F34518_elimError.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-21  |  4.8 KB  |  143 lines

  1. <xsl:stylesheet version="1.0" 
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:math="http://icl.com/saxon/java/java.lang.Math"
  4. >
  5.  
  6.   <xsl:variable name="vLn-2" select="0.69314718056"/>  
  7.   <xsl:template name="elimError">
  8.     <xsl:param name="pList" select="/.."/>
  9.     <xsl:param name="pOrder" select="-9999999"/>
  10.     <xsl:param name="pv2__N" select="0"/>
  11.     
  12.     <xsl:choose>
  13.       <xsl:when test="count($pList) < 3">
  14.         <xsl:copy-of select="$pList"/>
  15.       </xsl:when>
  16.       <xsl:otherwise>
  17.         <xsl:variable name="vOrder">
  18.             <xsl:choose>
  19.               <xsl:when test="$pOrder < -9999998">
  20.                 <xsl:call-template name="getOrder">
  21.                   <xsl:with-param name="pList" select="$pList"/>
  22.                 </xsl:call-template>
  23.               </xsl:when>
  24.               <xsl:otherwise>
  25.                 <xsl:value-of select="$pOrder"/>
  26.               </xsl:otherwise>
  27.             </xsl:choose>
  28.         </xsl:variable> 
  29.       
  30.         <xsl:variable name="v2__N">
  31.           <xsl:choose>
  32.               <xsl:when test="$pv2__N = 0">
  33.                   <xsl:call-template name="pow">
  34.                     <xsl:with-param name="base" select="2"/>
  35.                     <xsl:with-param name="pow" select="$vOrder"/>
  36.                   </xsl:call-template>
  37.               </xsl:when>
  38.               <xsl:otherwise>
  39.                   <xsl:value-of select="$pv2__N"/>
  40.               </xsl:otherwise>
  41.           </xsl:choose>
  42.         </xsl:variable>
  43.         
  44.         <xsl:element name="{name($pList[1])}">
  45.           <xsl:value-of select="($pList[2] * $v2__N - $pList[1]) 
  46.                                  div 
  47.                                   ($v2__N - 1)"/>
  48.         </xsl:element>
  49.         
  50.         <xsl:variable name="vNewList" select="$pList[position() > 1]"/>
  51.         
  52.         <xsl:variable name="vNewOrder">
  53.             <xsl:call-template name="getOrder">
  54.               <xsl:with-param name="pList" select="$vNewList"/>
  55.             </xsl:call-template>
  56.         </xsl:variable> 
  57.         <xsl:call-template name="elimError">
  58.             <xsl:with-param name="pList" select="$vNewList"/>
  59.             <xsl:with-param name="pOrder" select="$vNewOrder"/>
  60.             <xsl:with-param name="pv2__N" select="$v2__N"/>
  61.         </xsl:call-template>
  62.         
  63.       </xsl:otherwise>
  64.     </xsl:choose>
  65.   </xsl:template>
  66.   
  67.   <xsl:template name="getOrder">
  68.     <xsl:param name="pList" select="/.."/>
  69.     
  70.     <xsl:choose>
  71.       <xsl:when test="count($pList) < 3">1</xsl:when>
  72.       <xsl:otherwise>
  73.         <xsl:variable name="v1" select="($pList[1] - $pList[3])
  74.                                        div 
  75.                                          ($pList[2] - $pList[3])
  76.                                          - 1"/>
  77.         <xsl:variable name="v2">
  78.           <xsl:choose>
  79.             <xsl:when test="$v1 > 0">
  80.               <xsl:value-of select="$v1"/>
  81.             </xsl:when>
  82.             <xsl:when test="$v1 < 0">
  83.               <xsl:value-of select="(-1) * $v1"/>          
  84.             </xsl:when>
  85.             <xsl:otherwise>1</xsl:otherwise>
  86.           </xsl:choose>
  87.         </xsl:variable>
  88.         
  89.         <xsl:call-template name="roundLog2">
  90.           <xsl:with-param name="pX" select="string($v2)"/>
  91.         </xsl:call-template>
  92.       </xsl:otherwise>
  93.     </xsl:choose>
  94.   </xsl:template>
  95.   
  96.   <xsl:template name="roundLog2">
  97.     <xsl:param name="pX"/>
  98.     
  99.     <xsl:value-of select="math:round(math:log($pX) div $vLn-2)"/>
  100.   </xsl:template>
  101.   
  102.    <xsl:template name="pow">
  103.         <xsl:param name="base" select="1"/>
  104.         <xsl:param name="pow" select="0"/>
  105.         <xsl:param name="tmpResult" select="1"/>
  106.  
  107.         <xsl:variable name="result">
  108.             <xsl:choose>
  109.                 <xsl:when test="$pow >= 0">
  110.                     <xsl:value-of select="$tmpResult * $base"/>
  111.                 </xsl:when>
  112.                 <xsl:otherwise>
  113.                     <xsl:value-of select="$tmpResult div $base"/>
  114.                 </xsl:otherwise>
  115.            </xsl:choose>
  116.         </xsl:variable>
  117.  
  118.         <xsl:variable name="incr">
  119.             <xsl:choose>
  120.                 <xsl:when test="$pow >= 0">
  121.                     <xsl:value-of select="- 1"/>
  122.                 </xsl:when>
  123.                 <xsl:otherwise>
  124.                     <xsl:value-of select="1"/>
  125.                 </xsl:otherwise>
  126.             </xsl:choose>
  127.         </xsl:variable>
  128.  
  129.         <xsl:choose>
  130.             <xsl:when test="$pow = 0">
  131.                 <xsl:value-of select="$tmpResult"/>
  132.             </xsl:when>
  133.             <xsl:otherwise>
  134.                 <xsl:call-template name="pow">
  135.                     <xsl:with-param name="base" select="$base"/>
  136.                     <xsl:with-param name="pow" select="$pow + $incr"/>
  137.                     <xsl:with-param name="tmpResult" select="$result"/>
  138.                 </xsl:call-template>
  139.             </xsl:otherwise>
  140.         </xsl:choose>
  141.     </xsl:template>
  142.   
  143. </xsl:stylesheet>